﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using InformationSystem.Dao;
using InformationSystem.Entity;

namespace InformationSystem.Service
{
	/// <summary>
	/// Description of UserService.
	/// </summary>
	public class UserService:IService<User>
	{
		UserDao uDao = new UserDao();
		
		public UserService()
		{
		}

		#region IService implementation

		public bool add(User objct)
		{
			return uDao.add(objct);
		}

		public bool del(User objct)
		{
			return uDao.del(objct);
		}

		public bool update(User objct)
		{
			return uDao.update(objct);
		}

		public User query(User objct)
		{
			return uDao.query(objct);
		}

		public List<User> queryAll()
		{
			return uDao.queryAll();
		}

		#endregion
		
		public SQLiteDataAdapter getDisplayColumn()
		{
			String sql = "select id, name , age, phone, address from t_user where userType='2' order by id asc";
			
			return uDao.getDisplayColumn(sql);
		}
		
		
		public bool addOrUpdate(User user)
		{
			if(user.id > 0)
			{
				return update(user);
			}
			
			user.userType = ISUtils.getInstance().USER_TYPE_STUDENT;
			user.pwd = "123";
			
			return add(user);
		}
		
	}
}
